package zzc.javaWeb.javaWebHomew.servlet;


import zzc.javaWeb.javaWebHomew.dao.homeDaoimp;
import zzc.javaWeb.javaWebHomew.pojo.PageBean;
import zzc.javaWeb.javaWebHomew.pojo.ResBean;
import zzc.javaWeb.javaWebHomew.pojo.UserBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/Res")
public class ResServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResBean resBean=new ResBean();
        UserBean userBean = new UserBean();
        String tihao =req.getParameter("tihao");
        String xname =req.getParameter("name");
        System.out.println(xname);
        int th=0;
        int flag =-1;
        if (tihao!=null&&xname!=null){
            th=Integer.parseInt(tihao);

            resBean.setTid(th);
            resBean.setXname(xname);
            homeDaoimp homeDaoimp = new homeDaoimp();
            try {
              flag =homeDaoimp.addRes(resBean);

                  resp.sendRedirect("/Jer/res.jsp");


            } catch (SQLException throwables) {

               userBean.setId(th);
                try {
                    homeDaoimp.addCs(th);
                    resp.sendRedirect("/Jer/chongfu.html");
                } catch (SQLException e) {
                    e.printStackTrace();
                }

                // System.out.println("这是添加res用户的返回值"+flag);
                throwables.printStackTrace();
            }
        }

    }


}
